package com.ktjiaoyu.crm.mapper;

import com.ktjiaoyu.crm.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Insert("INSERT INTO sys_user(usr_name,usr_password,usr_role_id,usr_flag)"
    +"values (#{usrName},#{usrPassword},#{usrRoleId},#{usrFlag})")
    public int insert(User user);
    @Delete("delete from sys_user where usr_id=#{id}")
    public void delete(Long id);
    @Update("<script>UPDATE sys_user<set>" +
             "<if test=\"usrName != null\">usr_name = #{usrName},</if>"+
             "<if test=\"usrPassword != null\">usr_password = #{usrPassword},</if>"+
             "<if test=\"usrRoleId != null\">usr_role_id = #{usrRoleId},</if>"+
             "<if test=\"usrFlag != null\">usr_flag = #{usrFlag},</if></set>"+
             "WHERE usr_id = #{usrId}</script>")
    public void update(User user);
    @Select("select usr_id, usr_name, usr_password, usr_role_id, usr_flag from sys_user where usr_id=#{id}")
    @Results({@Result(column ="usr_id",property = "usr_id"),
            @Result(column ="usr_name",property = "usr_name"),
            @Result(column ="usr_password",property = "usr_password"),
            @Result(column ="usr_role_id",property = "usr_role_id"),
            @Result(column ="usr_flag",property = "usr_flag")
    })
    public User get(Long id);
    @Select("select usr_id, usr_name, usr_password, usr_role_id, usr_flag from sys_user")
    @Results({@Result(column ="usr_id",property = "usr_id"),
            @Result(column ="usr_name",property = "usr_name"),
            @Result(column ="usr_password",property = "usr_password"),
            @Result(column ="usr_role_id",property = "usr_role_id"),
            @Result(column ="usr_flag",property = "usr_flag")
    })
    public List<User> findAll();
}
